package com.axxc.cloud.demo;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TimeZone;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import com.axxc.cloud.pojo.User;

public class TestA {

	public static void main(String[] args) {

		// Double f = 0.00005585;
		// System.out.println(Double.doubleToLongBits(f));
		// m1(f);
		// m2(f);
		// m3(f);
		// m4(f); sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
		String result1 = String.format("%tF;小明%d岁,他住在%s,他的月工资有%.2f", new Date(), 25, "北京市", 16633.434);
		System.out.println(result1);// 输出:2018-08-24;小明25岁,他住在北京市,他的月工资有6633.44
		// System.out.println(String.format("该域名[%s]被访问了 [%d] 次.",15,15));
		// System.out.println("adv2424".substring(3, "adv2424".length()));
		// System.out.println("15527,15526,15525,15524,15523,15522,15521,15520,15519,15516,".split(",").length);
		// System.out.println(new Random().nextInt(3) + 1);
		System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.SIMPLIFIED_CHINESE).format(new Date()));
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
		sdf.setTimeZone(TimeZone.getTimeZone("GMT"));// 设置时区
		System.out.println(sdf.format(new Date()));
		// System.out.println(20 / 4);
		//
		// System.out.println(new Integer(54987).equals(new Integer(54987)));
		//
		// System.out.println(2 << 6);
		//
		// List<User> allShopLists = new ArrayList<User>();
		// User user2 = new User();
		// user2.setId(0);
		// user2.setUsername("熊");
		// user2.setPassword("48447646");
		// User user4 = new User();
		// user4.setId(1);
		// user4.setUsername("熊");
		// user4.setPassword("48447646");
		// User user5 = new User();
		// user5.setId(0);
		// user5.setUsername("a");
		// user5.setPassword("48447646");
		//
		//
		// allShopLists.add(user2);
		// allShopLists.add(user4);
		// allShopLists.add(user5);
		//
		//
		// Collections.sort(allShopLists, new Comparator<User>() {
		//
		// public int compare(User s1, User s2) {
		// // TODO Auto-generated method stub
		// int num = s1.getId().compareTo(s2.getId());
		// if(num == 0 ){
		// num = s1.getUsername().compareTo(s2.getUsername());
		// }
		// return num ;
		// }
		// });
		//
		//
		//
		// System.out.println(allShopLists);

		// System.out.println(Integer.valueOf("+99"));
		//
		// System.out.println(isNull(null));
		// System.out.println(isNull(Integer.valueOf("+99")));
		// System.out.println(isNull("+99"));
		// System.out.println(isNull(" "));
		// System.out.println(isNull(Integer.valueOf("-99")));
		//
		// System.out.println("6fbf471f2f235723115df5b28600c4f0".length());
		// System.out.println("96e87747170590636584005e9eb50b3b".length());
		// System.out.println("893adceaaab6ab18c1835657e74d7f7b".length());
		//
		// System.out.println(String.format("http://www.baidu.com?userid=%s&code=%s",
		// "135", "ghohfiupgn"));
		// int count = 0;
		// for (int i = 0; i < 10; i++) {
		// count = count++;// 先赋值再自增
		// }
		// System.out.println(count);
		// String[] a = "a,b,".split(",");
		// System.out.println(Arrays.toString(a));
		// String[] b = "a".split(",");
		// System.out.println(Arrays.toString(b));
		// String[] c = "a,".split(",");
		// System.out.println(Arrays.toString(c));
		// String[] d = "a,b,c,d".split(",");
		// System.out.println(Arrays.toString(d));
		// final String unbindInfo =
		// String.format("【智享城市】您的智享城市账号%s与微信昵称%s的授权绑定信息已经被解除", "15377539106",
		// "46853");
		// System.out.println(unbindInfo);

		System.out.println("Runtime: " + System.getProperty("java.vm.vendor") + " " + System.getProperty("java.vm.name")
				+ " " + System.getProperty("java.vm.version") + " ");

		// String longa = Integer.MAX_VALUE + 10*1L+"";
		// System.out.println("longa\t"+longa);
		// System.out.println(
		// String.format("Long转Integer值:{}", Integer.valueOf(longa)));// 报错,超过边界
		//

		List<String> list1 = new ArrayList<String>();
		List<Integer> list2 = new ArrayList<Integer>();
		System.out.println(list1.getClass() == list2.getClass());

	}

	public static void b(int fee) {
		System.out.println(fee);
	}

	public static void m1(double f) {
		BigDecimal bg = new BigDecimal(f);
		double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
		System.out.println(f1);
	}

	/**
	 * DecimalFormat转换最简便
	 */
	public static void m2(double f) {
		DecimalFormat df = new DecimalFormat("#.00");
		System.out.println(df.format(f));
	}

	/**
	 * String.format打印最简便
	 */
	public static void m3(double f) {
		System.out.println(String.format("%.2f", f));
	}

	public static void m4(double f) {
		NumberFormat nf = NumberFormat.getNumberInstance();
		nf.setMaximumFractionDigits(2);
		System.out.println(nf.format(f));
	}

	private static void testB() {
		List<Integer> lists = new ArrayList<Integer>();
		for (int i = 0; i < 19; i++) {
			lists.add(i);
		}

		int size = 10, num = 1;
		int totalPage = (int) Math.ceil(lists.size() * 1.0 / size);

		List<Integer> listTemp = new ArrayList<Integer>();
		if (num >= 0 && num < totalPage) {
			int offest = num * size;
			int length = offest + size;
			listTemp = lists.subList(offest, length > lists.size() ? lists.size() : length);
			System.out.println("第" + num + "轮:>>" + listTemp);
		}
	}

	@Test
	public static void testA() {

		Set<User> allShopSets = new HashSet<User>();

		List<User> myShopLists = new ArrayList<User>();
		User user1 = new User();
		user1.setId(1);
		user1.setUsername("熊");
		user1.setPassword("56464");
		User user3 = new User();
		user3.setId(3);
		user3.setUsername("熊");
		user3.setPassword("56464");
		myShopLists.add(user1);
		myShopLists.add(user3);
		User user5 = new User();
		user5.setId(4);
		user5.setUsername("熊");
		user5.setPassword("bbbbb");
		myShopLists.add(user5);

		List<User> allShopLists = new ArrayList<User>();
		User user2 = new User();
		user2.setId(1);
		user2.setUsername("熊");
		user2.setPassword("48447646");
		User user4 = new User();
		user4.setId(4);
		user4.setUsername("熊");
		user4.setPassword("48447646");
		allShopLists.add(user2);
		allShopLists.add(user4);

		for (User user : allShopLists) {
			allShopSets.add(user);
		}

		a: for (User user : myShopLists) {// 134
			for (User uu2 : allShopSets) {// 14 11a 31a 34ab 41a 44a
				System.out.println(user.getId());
				System.out.println(uu2.getId());
				if (user.getId() == uu2.getId()) {
					System.out.println("a");// 11a 31 34b 41 44a
					uu2.setPassword("aaa");
					continue a;
				}
			}
			System.out.println("b");
			allShopSets.add(user);// --->134
		}

		System.out.println(allShopSets.size() + "条");
		System.out.println(allShopSets);

	}

	public static boolean isNull(Object obj) {
		boolean flag = false;
		if (obj == null) {
			flag = true;
		} else {
			if (obj instanceof String) {
				if (StringUtils.isBlank(String.valueOf(obj))) {
					flag = true;
				}
			} else if (obj instanceof Integer) {
				if (StringUtils.isBlank(String.valueOf(obj))) {
					flag = true;
				} else {
					if (((Integer) obj).intValue() < 1) {
						flag = true;
					}
				}
			}
		}
		return flag;
	}

}
